

#include "cocos2d.h"

#include "Common\Misc\CmnFunc.h"

#include "CmdDef.h"
#include "JumpBlock.h"

using namespace cocos2d;


JumpBlock::JumpBlock()
{
	CCSprite::init();
}




void JumpBlock::SetColor(int _color)
{
	color = _color;

	if(color == eColor_Non) return;

	char colorText[1024];
	sprintf(colorText, "color%d.png", color);


	CCSprite* shap_sp= new CCSprite();
	shap_sp->initWithSpriteFrameName(colorText);

	CCPoint pos = ccp(0,0);
	switch(id){
	case 1:
		pos = ccp(125,40);
		shap_sp->setScale(0.25);
		break;
	case 2:
		pos = ccp(100,80);
		shap_sp->setScale(0.3f);
		break;
	case 3:
		pos = ccp(100,125);
		shap_sp->setScale(0.3f);
		break;
	}

	this->addChild(shap_sp);
	shap_sp->setPosition(pos);

	/*switch(color){
	case eColor_Red:
		break;
	case eColor_Yellow:
		setColor(ccc3(255, 255,0));
		break;
	case eColor_Blue:
		setColor(ccc3(0, 0,255));
		break;
	case eColor_Orange:
		setColor(ccc3(255, 128,0));
		break;
	case eColor_Purple:
		setColor(ccc3(255, 0,255));
		break;
	case eColor_Green:
		setColor(ccc3(0, 255,0));
		break;
	case eColor_Black:
		setColor(ccc3(255, 255,255));
		break;
	default:break;
	}*/
}


void JumpBlock::SetShap(int _shap)
{
	shap=_shap;

	if(shap == eShap_Non) return;

	char shapText[1024];
	switch(shap){
	case eShap_Triangle:
		{
			sprintf(shapText, "%s", "shap1.png");
		}break;
	case eShap_Quadrilateral:
		{
			sprintf(shapText, "%s", "shap2.png");
		}break;
	case eShap_Circle:
		{
			sprintf(shapText, "%s", "shap3.png");
		}break;

	default:
		{
			sprintf(shapText, "");
		}break;
	}



	CCSprite* shap_sp= new CCSprite();
	shap_sp->initWithSpriteFrameName(shapText);

	CCPoint pos = ccp(0,0);
	switch(id){
	case 1:
		pos = ccp(125,40);
		shap_sp->setScale(0.45f);
		break;
	case 2:
		pos = ccp(100,80);
		shap_sp->setScale(0.6f);
		break;
	case 3:
		pos = ccp(100,125);
		shap_sp->setScale(0.6f);
		break;
	}

	this->addChild(shap_sp);
	shap_sp->setPosition(pos);


    CCActionInterval *rot1 = CCRotateBy::create(4, 360);
	CCRepeatForever *repeata = CCRepeatForever::create( rot1 );
	shap_sp->runAction(repeata);
}


void JumpBlock::SetNumber(int _number)
{
	number =_number;
	if(number == 0) return;

	char numberText[1024];
	sprintf(numberText, "%d", number);

	CCLabelTTF* numberLabel = CCLabelTTF::create(numberText, "Arial", 20);
	this->addChild(numberLabel);

	CCPoint pos = ccp(0,0);
	switch(id){
	case 1:
		pos = ccp(125,40);
		break;
	case 2:
		pos = ccp(100,80);
		break;
	case 3:
		pos = ccp(100,125);
		break;
	}
	numberLabel->setPosition(pos);


}




cocos2d::CCPoint JumpBlock::GetFoothold()
{
	CCSize s = getContentSize();
	CCPoint pos = ccpAdd(getPosition() , ccp(0,s.height-100));

	switch(id ){
	case 1:
		pos = ccpSub(pos , ccp(5,0));
		pos = ccpSub(pos , ccp(0,30));
		break;
	case 2:
		pos = ccpSub(pos , ccp(-10,25));
		break;
	case 3:
		pos = ccpSub(pos , ccp(-10,26));
		break;
	}

	return pos;
}




void JumpBlock::Wave()
{
	//CCActionInterval* act =  CCTwirl::create(ccp(this->getContentSize().width/2,this->getContentSize().height/2), 1, 0.5f, ccg(1,1), 1.0f); 

	CCSize s = getContentSize();
	CCPoint twirlPos = ccp(this->getPositionX() +s.width*3/4,0);

	/*switch(id ){
	case 1:
		twirlPos = ccp(this->getPositionX() +s.width/2,0);
		break;
	case 2:
		twirlPos = ccp(this->getPositionX() +s.width/2,0);
		break;
	case 3:
		twirlPos = ccp(this->getPositionX() +s.width/2,0);
		break;
	}*/

	CCActionInterval* act =  CCTwirl::create(1.0f,CCSizeMake(1.0f,1.0f), twirlPos, 1, 0.10f ); 
    //CCActionInterval* waves = CCWaves::create(1, CCSizeMake(5,5), 1, 1, true, true);
	runAction(act);
}



